package cn.stylefeng.guns.modular.time.controller;

import cn.stylefeng.guns.modular.time.entity.Notification;
import cn.stylefeng.guns.modular.time.model.request.NotificationRequest;
import cn.stylefeng.guns.modular.time.service.NotificationService;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@ApiResource(name = "消息通知")
public class NotificationController {

    @Resource
    private NotificationService notificationService;

    /** 分页查询通知 */
    @GetResource(name = "分页查询通知", path = "/notification/page")
    public ResponseData<PageResult<Notification>> page(NotificationRequest request) {
        return new SuccessResponseData<>(notificationService.findPage(request));
    }

    /** 新增通知 */
    @PostResource(name = "新增通知", path = "/notification/add")
    public ResponseData<Void> add(@RequestBody @Validated(NotificationRequest.add.class) NotificationRequest request) {
        notificationService.add(request);
        return new SuccessResponseData<>();
    }

    /** 删除通知 */
    @PostResource(name = "删除通知", path = "/notification/delete")
    public ResponseData<Void> delete(@RequestBody @Validated(NotificationRequest.delete.class) NotificationRequest request) {
        notificationService.delete(request);
        return new SuccessResponseData<>();
    }

    /** 通知详情 */
    @GetResource(name = "通知详情", path = "/notification/detail")
    public ResponseData<Notification> detail(@Validated(NotificationRequest.detail.class) NotificationRequest request) {
        return new SuccessResponseData<>(notificationService.detail(request));
    }
}